﻿var over = 0;

var thisPage = {
    first: 0,
    // 得到信息数据
    GetEntityData: function () {
        let data = new Object();
        data.username = $("#EmployeeNo").val();
        data.oldPassword = $("#OldPassword").val();
        data.newPassword = $("#NewPassword").val();

        return JSON.stringify(data);
    },
    ChangePassword: function () {
        //step 1、进行页面验证，失败则返回
        if (!$("#form_data").valid())
            return;

        $.ajax({
            type: "POST",
            url: parent.basePath + "/admin/password/change.html",
            timeout: 30 * 1000,
            data: thisPage.GetEntityData(),
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            beforeSend: function () {
                //showLoadmask();
            }
        }).done(function (data) {
            if (data.success > 0) {
                ShowSuccessMessagePanel('密码更改成功。');
            } else {
                ShowErrorMessagePanel('密码更改失败，请重新操作。');
            }
        }).fail(function (data) {
            ajaxError(data, 1);
        }).always(function () {
            //hideLoadmask();
        });
    }
};

//-----------------------------------------------------------------------------
// 页面初始化
//-----------------------------------------------------------------------------
function onPageReady() {
    // 用于判断表单是否有更改
    $("#form_data :input").change(function () {
        $("#form_data").data("changed", true);
    });
    $("#search_btn").hide();                  // 更改密码无需搜索，隐藏搜索按钮
    $("#form_data").data("changed", false);   // 初始化form数据提交状态

    $("#OldPassword").focus();
    $('#loading').hide();
}

// 画面大小或者位置移动
function onPageResize() {
    let w = $(window).width();
    let h = $(window).height();

    //$("#wrapper__data_content").css({height: h + 20});
    //$(".data__table_wrapper").css({width: w - 40, height: h - 30});

    over = 1;
}

//-----------------------------------------------------------------------------
// 验证函数
//-----------------------------------------------------------------------------
$(function () {
    $("#form_data").validate({
        // Step 1：设置验证规则和错误消息
        rules: {
            _OldPassword: "required",
            _NewPassword: {
                required: true,
                minlength: 5
            },
            _ConfirmPassword: {
                required: true,
                minlength: 5,
                equalTo: "#NewPassword"
            }
        },
        messages: {
            _OldPassword: "请填写旧密码。",
            _NewPassword: {
                required: "密码必须输入。",
                minlength: "密码最小长度为5。"
            },
            _ConfirmPassword: {
                required: "重复密码必须输入。",
                minlength: "重复密码最小长度为5。",
                equalTo: "密码与重复密码要一致。"
            }
        },
        // Step 2：设置验证触发事件
        onclick: false,
        onfocusout: false,
        onfocusin: false,
        onkeyup: false,
        onkeydown: false,
        focusInvalid: false,
        // Step 3：设置错误信息提示
        showErrors: window.showErrors  //使用自定义的错误显示方法
    });
});